/* Turska UI library
 * Copyright 2003-2008 Jetro Lauha
 * All rights reserved.
 * Web: http://iki.fi/jetro/ or http://jet.ro
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of EITHER:
 *   (1) The GNU Lesser General Public License as published by the Free
 *       Software Foundation; either version 2.1 of the License, or (at
 *       your option) any later version. The text of the GNU Lesser
 *       General Public License is included with this library in the
 *       file LICENSE-LGPL.txt.
 *   (2) The BSD-style license that is included with this library in
 *       the file LICENSE-BSD.txt.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
 * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
 *
 * $Id: UIImageSDL.cpp,v 1.3 2008/03/27 11:44:28 tonic Exp $
 * $Revision: 1.3 $
 */

#include <assert.h>
#include "SDL.h"

#include "UI.h"



UIImageSDL::UIImageSDL(SDL_Surface *surface, UINT32 flags) :
    UIImage(surface->w, surface->h, NORMAL, flags),
    mSurface(surface)
{
    assert(surface != NULL);
    mTargetWidth = surface->w;
    mTargetHeight = surface->h;
}


UIImageSDL::~UIImageSDL()
{
    delete mSurface;
}


void UIImageSDL::setColor(UINT8 red, UINT8 green, UINT8 blue, UINT8 alpha)
{
    // TODO
}


void UIImageSDL::setColor(FLOAT red, FLOAT green, FLOAT blue, FLOAT alpha)
{
    // TODO
}


void UIImageSDL::draw(UINT drawMode, UINT32 flags, INT32 x, INT32 y)
{
    SDL_Surface *videoSurface = SDL_GetVideoSurface();
    SDL_Rect dstRect;
    SDL_Rect srcRect;

    // TODO - make real implementation
    srcRect.x = srcRect.y = 0;
    srcRect.w = mWidth;
    srcRect.h = mHeight;
    dstRect.x = x;
    dstRect.y = y;
    dstRect.w = mTargetWidth;
    dstRect.h = mTargetHeight;
    if (mFlags & CENTER)
    {
        dstRect.x -= mTargetWidth / 2;
        dstRect.y -= mTargetHeight / 2;
    }
    SDL_BlitSurface(mSurface, &srcRect, videoSurface, &dstRect);
}
